﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kocic.RepositoryManagement.SystemFile;

namespace Sample.Run.SystemFile
{
    public class BasicFileRepositoryManager : SystemFileRepositoryManager<LineObject, FileContext>
    {
        public BasicFileRepositoryManager()
        {

        }

        public BasicFileRepositoryManager(FileContext context)
            : base(context)
        {
        }

        public override LineObject RetrieveSingle(object searchValue)
        {
            Int32 lineNumber = Convert.ToInt32(searchValue);

            return this.DataSource.Lines.Where(l => l.LineNumber == lineNumber).SingleOrDefault();
        }

        public override IEnumerable<LineObject> RetrieveMultiple()
        {
            return this.DataSource.Lines.Select(c => c);
        }

        public override IEnumerable<LineObject> RetrieveMultiple(object searchValue)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<String> RetrieveMultipleAsString()
        {
            var results = from l in this.DataSource.Lines
                          select new String(l.Contents.ToCharArray());

            return results;
        }
    }
}
